fix(image): use standardized HTTP client for ECR authentication#9322
Merged
Conversation
|
Manveer Singh seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
| func (e *ECRClient) GetCredential(ctx context.Context) (username, password string, err error) { | ||
| input := &ecr.GetAuthorizationTokenInput{} | ||
| result, err := e.Client.GetAuthorizationToken(ctx, input) | ||
| result, err := e.Client.GetAuthorizationToken(ctx, input, func(options *ecr.Options) { |
Contributor
There was a problem hiding this comment.
What do you think about adding xhttp.Client to ecr config instead of this place:
diff --git a/pkg/fanal/image/registry/ecr/ecr.go b/pkg/fanal/image/registry/ecr/ecr.go
index c9bb0dea5..cbeb84334 100644
--- a/pkg/fanal/image/registry/ecr/ecr.go
+++ b/pkg/fanal/image/registry/ecr/ecr.go
@@ -6,6 +6,7 @@ import (
"regexp"
"strings"
+ xhttp "github.com/aquasecurity/trivy/pkg/x/http"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
@@ -37,10 +38,15 @@ func getSession(domain, region string, option types.RegistryOptions) (aws.Config
return config.LoadDefaultConfig(
context.TODO(),
config.WithRegion(region),
+ config.WithHTTPClient(xhttp.Client()),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(option.AWSAccessKey, option.AWSSecretKey, option.AWSSessionToken)),
)
}
- return config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))
+ return config.LoadDefaultConfig(
+ context.TODO(),
+ config.WithRegion(region),
+ config.WithHTTPClient(xhttp.Client()),
+ )
}
func (e *ECR) CheckOptions(domain string, option types.RegistryOptions) (intf.RegistryClient, error) {My thoughts:
- We won't have to add
xhttp.Client()again if we run another function frome.client. - All configurations will be in one place.
Contributor
Author
There was a problem hiding this comment.
This is better way to do it. Updated the code.
yutatokoi
referenced
this pull request
in yutatokoi/trivy
Aug 24, 2025
alexlebens
pushed a commit
to alexlebens/infrastructure
that referenced
this pull request
Sep 3, 2025
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [mirror.gcr.io/aquasec/trivy](https://www.aquasec.com/products/trivy/) ([source](https://github.com/aquasecurity/trivy)) | minor | `0.65.0` -> `0.66.0` | --- ### Release Notes <details> <summary>aquasecurity/trivy (mirror.gcr.io/aquasec/trivy)</summary> ### [`v0.66.0`](https://github.com/aquasecurity/trivy/blob/HEAD/CHANGELOG.md#0660-2025-09-02) [Compare Source](aquasecurity/trivy@v0.65.0...v0.66.0) ##### Features - add timeout handling for cache database operations ([#​9307](aquasecurity/trivy#9307)) ([235c24e](aquasecurity/trivy@235c24e)) - **misconf:** added audit config attribute ([#​9249](aquasecurity/trivy#9249)) ([4d4a244](aquasecurity/trivy@4d4a244)) - **secret:** implement streaming secret scanner with byte offset tracking ([#​9264](aquasecurity/trivy#9264)) ([5a5e097](aquasecurity/trivy@5a5e097)) - **terraform:** use .terraform cache for remote modules in plan scanning ([#​9277](aquasecurity/trivy#9277)) ([298a994](aquasecurity/trivy@298a994)) ##### Bug Fixes - **conda:** memory leak by adding closure method for `package.json` file ([#​9349](aquasecurity/trivy#9349)) ([03d039f](aquasecurity/trivy@03d039f)) - create temp file under composite fs dir ([#​9387](aquasecurity/trivy#9387)) ([ce22f54](aquasecurity/trivy@ce22f54)) - **cyclonedx:** handle multiple license types ([#​9378](aquasecurity/trivy#9378)) ([46ab76a](aquasecurity/trivy@46ab76a)) - **fs:** avoid shadowing errors in file.glob ([#​9286](aquasecurity/trivy#9286)) ([b51c789](aquasecurity/trivy@b51c789)) - **image:** use standardized HTTP client for ECR authentication ([#​9322](aquasecurity/trivy#9322)) ([84fbf86](aquasecurity/trivy@84fbf86)) - **misconf:** ensure ignore rules respect subdirectory chart paths ([#​9324](aquasecurity/trivy#9324)) ([d3cd101](aquasecurity/trivy@d3cd101)) - **misconf:** ensure module source is known ([#​9404](aquasecurity/trivy#9404)) ([81d9425](aquasecurity/trivy@81d9425)) - **misconf:** preserve original paths of remote submodules from .terraform ([#​9294](aquasecurity/trivy#9294)) ([1319d8d](aquasecurity/trivy@1319d8d)) - **misconf:** use correct field log\_bucket instead of target\_bucket in gcp bucket ([#​9296](aquasecurity/trivy#9296)) ([04ad0c4](aquasecurity/trivy@04ad0c4)) - persistent flag option typo ([#​9374](aquasecurity/trivy#9374)) ([6e99dd3](aquasecurity/trivy@6e99dd3)) - **plugin:** don't remove plugins when updating index.yaml file ([#​9358](aquasecurity/trivy#9358)) ([5f067ac](aquasecurity/trivy@5f067ac)) - **python:** impove package name normalization ([#​9290](aquasecurity/trivy#9290)) ([1473e88](aquasecurity/trivy@1473e88)) - **repo:** preserve RepoMetadata on FS cache hit ([#​9389](aquasecurity/trivy#9389)) ([4f2a44e](aquasecurity/trivy@4f2a44e)) - **repo:** sanitize git repo URL before inserting into report metadata ([#​9391](aquasecurity/trivy#9391)) ([1ac9b1f](aquasecurity/trivy@1ac9b1f)) - **sbom:** add support for `file` component type of `CycloneDX` ([#​9372](aquasecurity/trivy#9372)) ([aa7cf43](aquasecurity/trivy@aa7cf43)) - suppress debug log for context cancellation errors ([#​9298](aquasecurity/trivy#9298)) ([2458d5e](aquasecurity/trivy@2458d5e)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4zNS4xIiwidXBkYXRlZEluVmVyIjoiNDEuMzUuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiaW1hZ2UiXX0=--> Reviewed-on: https://gitea.alexlebens.dev/alexlebens/infrastructure/pulls/1367 Co-authored-by: Renovate Bot <renovate-bot@alexlebens.net> Co-committed-by: Renovate Bot <renovate-bot@alexlebens.net>
This was referenced Sep 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an issue where the
--insecureflag was not being respected during ECR authentication. The ECR client was using the AWS SDK's default HTTP client, which didn't inherit Trivy's global TLS configuration settings.Changes
xhttp.Client()for ECRconfig which properly inherits the global--insecure` flag setting and other HTTP transport configurations.--insecureflagRelated issues
Checklist